<#assign resources="${rc.contextPath}/resources">
<#assign path="${rc.contextPath}">
<!DOCTYPE html>
<html lang="zh_CN">
<head>
<meta charset="UTF-8">

	<title>品牌购首页</title>
    <script >
		var path="${path}";
		var searchCondition='${searchCondition}';
		var marketId='${marketId}';
		
	</script>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link href="${resources}/plugins/fontAwesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="${resources}/css/common.css" rel="stylesheet" type="text/css">
    <link href="${resources}/css/brandIndex.css" rel="stylesheet" type="text/css">
     <#include "setwxshare.ftl"/>

</head>


<body>

 <div id="container">  
    <!--header-->
    <div class="header">
        <!--logo-->
        <a href="javascript:history.back(-1);" class="fa fa-chevron-left back"></a>
        <!--搜索框
        <form class="search" >
            <input id="search" type="search" placeholder="输入商家、品类、商圈">
            <i class="fa fa-search searchIcon" aria-hidden="true" onclick="commoditysearch()"></i>
        </form>
        -->
        <!--<a href="javascript:void(0)" class="fa fa-map-marker position"></a>-->
    </div>
     <!--热搜页-->
    <div class="hotSearch">
        <div class="searchTitle">热门商品</div>
        <ul id="hotsearch">
        	
        </ul>
    </div>
	<input type="hidden" id="marketId" value="${marketId}">
  <!--
    <div class="address">当前：
        <span class="position">宝安区</span>
        <span class="refresh">
            <i class="fa fa-repeat" aria-hidden="true"></i>
        </span>
    </div>
-->
    <div class="detail" style="top:50px;">
        <div id="tipdiv">
            <ul class="goods" id="goodsShow" >
            	
                
            </ul>
            
           <div id="tip" class="tip" >上滑加载更多..</div>
        </div>
    </div>

    <a class="fa fa-shopping-cart shopping-cart" href="${path}/manage/commodityCart/cartShow?marketId=${marketId}" aria-hidden="true"></a>

</div>
<script src="${resources}/plugins/jquery/2.2.2/jquery.min.js"></script>
<script src="${resources}/js/iscroll-probe.js"></script>
<script src="${resources}/js/homeGoodsIndex.js"></script>
<script src="${resources}/js/score.js"></script>
<script>
	

    //显示热搜
    $("#search").on("focus", function () {
        $(".hotSearch").show();
    });
    
    $("#search").on("click", function (e) {
        e.stopPropagation();
    });

    //隐藏热搜
    $("#container").on("click",function(){
    	$(".hotSearch").hide();
    })
	
	$(function(){
    	main.scroll();
		$("#search").val('${searchCondition}');
		commoditysearch();
		search();
	})
	
		//主页面查询
		function commoditysearch(){
		  $("#goodsShow li").remove();
		  $.ajax({
        		type:"post",
	        	url:"${path}/commodity/search",
	        	data:{
	        		"search":'${searchCondition}',
	        		"marketId":'${marketId}',
	        		"Id":0
	        	},
        		success:function(resultjson){	
        			if('000' == resultjson.code){
        				var html = "";
        				if(resultjson.result.length>0){
        				
        				
	        				for (var i = 0; i < resultjson.result.length; i++) {
	        					 html += '<li value="'+resultjson.result[i].goods.id+'">';
	        					 html += '<a href="${path}/commodity/goodsinfo?goodsId='+resultjson.result[i].goods.id+'">';
	        					 html += '<div class="goods-pic">';
	        					 html += '<img src="'+resultjson.result[i].goods.picurl+'"></div>';
	        					 html += '<h3>'+resultjson.result[i].goods.name+'</h3>';
	        					 html += '<div class="score">';
								  if(resultjson.result[i].score==0){
								 	html += '<span class="scoreCon" data-score="10"> </span>';
								 }else{
									html += '<span class="scoreCon" data-score="'+resultjson.result[i].score+'"> </span>';
								 }
	        					 html += ' </div>';
	        					 html += ' <div class="price">￥'+resultjson.result[i].goods.price+'元</div>';
	        					 html += ' </a> ';
	        				}	
	        				 $("#goodsShow").append(html);
	        				 
	        				
		        		    	/* 评分 */
			   				 score($(".scoreCon"));
			   				 myScroll.refresh();
		       				 main.max = myScroll.maxScrollY;
        				}
        				
        				if(resultjson.result.length==0){
	        					$("#tip").text("暂无商品");
	        				}else if(resultjson.result.length<20){
	            				$("#loading").hide();
				  	            $("#tip").hide();
            				}else if(resultjson.result.length>=20){
	 	  		            	$("#loading").hide();
	 			  	            $("#tip").show();
	 			  	            canLoad=true;
	 	  		            }
        			}
        		}
        	})
		
		}
		
		
		//查询热搜词
		function search(){
			$.ajax({
	        		type:"post",
	        		async:false, 
		        	url:"${path}/search/searchShow?marketId=${marketId}",
	        		success:function(resultjson){	
	        			if('000' == resultjson.code){
	        				var html = "";
	        				for (var i = 0; i < resultjson.result.length; i++) {
	        					 html += '<li id="hotSearch_'+resultjson.result[i].id+'" data-val="'+resultjson.result[i].hotsearch+'"><a  href="javascript:void(0)" onclick="hotSearch('+resultjson.result[i].id+')">'+resultjson.result[i].hotsearch+'</a></li>';
	        					 $("#no").remove(); 
	        				}
	        				$("#hotsearch").append(html);
	        			}
	        		}
	        })
		}
		//热搜词触发事件
		function hotSearch(hotsearch){
			 $("#search").val($("#hotSearch_"+hotsearch).data("val"));
			 commoditysearch();
		}
		
</script>
</body>
</html>
 

 
